*************************************************************************************************************
*Table B.1: Effects on value received using alternative specifications
*This table reports alternative specifications for Panel B in Table 3 by reporting models with March data only, pooled data with a linear trend, and pooled data without baseline lag
*************************************************************************************************************

*******************************************************************************
use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear

* Keep if surveyed or classified as ghost
keep if ss_code == "SS01" | ghost_final == 1

svyset [pw = pweight]


count if ghost_final == 1
scalar ghosts = r(N)
scalar obs = 3960   

*Get relative weights of AAY and PH rationcard holders by whether RC is in an urban area
sum pweight if rationcardtype == "AAY" & isurban == 0
scalar AAY_weight0 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 0
scalar PH_weight0 = r(sum)

sum pweight if rationcardtype == "AAY" & isurban == 1
scalar AAY_weight1 = r(sum)

sum pweight if rationcardtype == "PH" & isurban == 1
scalar PH_weight1 = r(sum)

*****************************
* March only 
*****************************


local tflist ""
local tflist_noBL ""

loc ration "rice wheat sugar salt kero"
foreach rat of local ration {

count
scalar obs = 3960

gen bl_var = value_`rat'_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1



qui svy: mean value_`rat'_mar17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)


*Statutory NIC entitlement
qui svy: mean stat_ent_value_`rat'_mar17 if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_value_`rat'_mar17 if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_value_`rat'_mar17 if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_value_`rat'_mar17 if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)

scalar avg_stat_ent_value_`rat' = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)


eststo mar_`rat': xi: reg value_`rat'_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs


tempfile mar_`rat'
parmest, label saving("`mar_`rat''")
local tflist_noBL "`tflist_noBL' `mar_`rat''"


eststo mar_`rat'BL: xi: reg value_`rat'_mar17 treatment bl_var bl_var_mi i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs

tempfile mar_`rat'BL
parmest, label saving("`mar_`rat'BL'")
local tflist "`tflist' `mar_`rat'BL'"

drop bl_var*
}


*Total Value
*Average entitlement value_total (listed in summary stats portion of table)

count
scalar obs = 3960

gen bl_var = value_total_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1

*Statutory NIC entitlement
qui svy: mean stat_ent_value_total_mar17 if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_value_total_mar17 if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_value_total_mar17 if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_value_total_mar17 if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)

scalar avg_stat_ent_value_total = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)



qui svy: mean value_total_mar17 if treatment == 0
qui estat sd
matrix Mean0 = r(mean)

eststo mar_total: xi: reg value_total_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs


eststo mar_totalBL: xi: reg value_total_mar17 treatment bl_var bl_var_mi i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs

drop bl_var*

preserve

dsconcat `tflist', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local estname: word `i' of `tflist'
local rat: word `i' of `ration'

estimates restore mar_`rat'BL


mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)

}


restore


preserve


dsconcat `tflist_noBL', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local estname: word `i' of `tflist_noBL'
local rat: word `i' of `ration'

estimates restore mar_`rat'



mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)
}

restore


*****************************
* Pooled
*****************************

local tflist ""
local tflist_noBL ""
local tflist_trend ""
local tflist_trend_noBL ""


loc ration "rice wheat sugar salt kero"
foreach rat of local ration {


*gen bl_var = value_total_y0
gen bl_var = value_`rat'_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1

*Estimation
preserve


keep value_`rat'_mar17 value_`rat'_feb17 value_`rat'_jan17 bl_var bl_var_mi treatment strata pweight block_code uid rationcardtype stat_ent_value_`rat'* rationcardtype isurban
gen value_`rat'3 = value_`rat'_mar17
gen value_`rat'2 = value_`rat'_feb17
gen value_`rat'1 = value_`rat'_jan17
drop value_`rat'_mar17 value_`rat'_feb17 value_`rat'_jan17
rename stat_ent_value_`rat'_mar17 stat_ent_value_`rat'3
rename stat_ent_value_`rat'_feb17 stat_ent_value_`rat'2
rename stat_ent_value_`rat'_jan17 stat_ent_value_`rat'1
reshape long value_`rat' stat_ent_value_`rat', i(uid) j(month)

count
scalar obs_all = 3*3960

*Statutory NIC entitlement
qui svy: mean stat_ent_value_`rat' if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_value_`rat' if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_value_`rat' if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_value_`rat' if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)

scalar avg_stat_ent_value_`rat' = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)

 
gen treatmentXmonth=treatment*month

qui svy: mean value_`rat' if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)


eststo `rat'pool1: xi: reg value_`rat' treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs_all

tempfile `rat'pool1
parmest, label saving("``rat'pool1'")
local tflist_noBL "`tflist_noBL' ``rat'pool1'"


eststo `rat'pool2: xi: reg value_`rat' treatment i.strata month treatmentXmonth [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs_all

tempfile `rat'pool2
parmest, label saving("``rat'pool2'")
local tflist_trend_noBL "`tflist_trend_noBL' ``rat'pool2'"

eststo `rat'poolBL1: xi: reg value_`rat' treatment i.strata bl_var bl_var_mi [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs_all

tempfile `rat'poolBL1
parmest, label saving("``rat'poolBL1'")
local tflist "`tflist' ``rat'poolBL1'"

eststo `rat'poolBL2: xi: reg value_`rat' treatment i.strata month treatmentXmonth bl_var bl_var_mi [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_`rat'
estadd scalar percent_obs 100*e(N)/obs_all

tempfile `rat'poolBL2
parmest, label saving("``rat'poolBL2'")
local tflist_trend "`tflist_trend' ``rat'poolBL2'"

restore
drop bl_var*
}


*Total value
count
scalar obs = 3960

gen bl_var = value_total_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1


preserve
keep uid value_*17 bl_var bl_var_mi treatment strata pweight block_code ss_code  stat_ent_value_*17 rationcardtype isurban ghost_final b20_adr_seed_hh_0_1 
rename stat_ent_value_total_mar17 stat_ent_value_total3
rename stat_ent_value_total_feb17 stat_ent_value_total2
rename stat_ent_value_total_jan17 stat_ent_value_total1
rename value_total_mar17 value_total3 
rename value_total_feb17 value_total2
rename value_total_jan17 value_total1
reshape long value_total stat_ent_value_total , i(uid) j(month)

count

scalar obs_all = 3*3960


*Statutory NIC entitlement
qui svy: mean stat_ent_value_total if rationcardtype == "AAY" & isurban == 0
qui estat sd
matrix MeanAAY0s = r(mean)

qui svy: mean stat_ent_value_total if rationcardtype == "PH" & isurban == 0
qui estat sd
matrix MeanPH0s = r(mean)

qui svy: mean stat_ent_value_total if rationcardtype == "AAY" & isurban == 1
qui estat sd
matrix MeanAAY1s = r(mean)

qui svy: mean stat_ent_value_total if rationcardtype == "PH" & isurban == 1
qui estat sd
matrix MeanPH1s = r(mean)

scalar avg_stat_ent_value_total = (AAY_weight0*`=MeanAAY0s[1,1]' + PH_weight0*`=MeanPH0s[1,1]' + AAY_weight1*`=MeanAAY1s[1,1]' + PH_weight1*`=MeanPH1s[1,1]')/(AAY_weight0 + PH_weight0 + AAY_weight1 + PH_weight1)


gen treatmentXmonth=treatment*month



qui svy: mean value_total if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

svy: mean value_total if treatment == 1 & b20_adr_seed_hh_0_1 == 1


eststo totalpool1: xi: reg value_total treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs_all

eststo totalpool2: xi: reg value_total treatment i.strata month treatmentXmonth [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs_all

eststo totalpoolBL1: xi: reg value_total treatment i.strata bl_var bl_var_mi [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs_all

eststo totalpoolBL2: xi: reg value_total treatment i.strata month treatmentXmonth bl_var bl_var_mi [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar stat_ent_mean = avg_stat_ent_value_total
estadd scalar percent_obs 100*e(N)/obs_all

restore
drop bl_var*

preserve

dsconcat `tflist', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'poolBL1


mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)
}

restore





preserve
dsconcat `tflist_noBL', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'pool1



mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)
}

restore



preserve
dsconcat `tflist_trend', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'poolBL2



mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)
}

restore



preserve
dsconcat `tflist_trend_noBL', subset(parm p in 1) dsn(ds_ration) 
qqvalue p, method(yekutieli) qvalue(qval)
mkmat qval

 
forval i = 1/5 {
local rat: word `i' of `ration'
estimates restore `rat'pool2



mat bet=e(b)                   

mat bet[1,1]=qval[`i',1]             
mat list bet      
estadd matrix qvalue = bet               
                                            
mat list e(qvalue)
}

restore


loc tabname "${OutputDir}/TableB_1.tex" 
cd "${adoDir}"
loc nc 6

				
MultiPartTabStart, ///
			ncol(`nc') tabname(`tabname') ///
			colnames("Total" "Rice" "Wheat" "Sugar" "Salt" "Kerosene") width("\hsize")			
				
** March only 		
MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel A: March only")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("*totalBL *riceBL *wheatBL *sugarBL *saltBL *keroBL") ///
				drop(_cons _Istrata* bl_var*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment" , elist(treatment \addlinespace )  )  ///
				stats(control_mean N,  ///
					labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))

					
** Pooled with linear trend 	
MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel B: Pooled data with linear trend")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("totalpoolBL2 ricepoolBL2 wheatpoolBL2 sugarpoolBL2 saltpoolBL2 keropoolBL2") ///
				drop(_cons _Istrata* bl_var*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment"  month "Month" treatmentXmonth "Treatment X Month" , ///
				elist(treatment \addlinespace  month \addlinespace treatmentXmonth \addlinespace)  ) ///
				stats(control_mean N, labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))

** Pooled with no baseline lag 		

MultiPartTabPanelStart, ///
			ncol(`nc') tabname(`tabname') ///
			panelstring("Panel C: Pooled data with no baseline lag")
			
MultiPartTabPanelEnd, ///
				ncol(`nc') tabname(`tabname') ///
				models("totalpool1 ricepool1 wheatpool1 sugarpool1 saltpool1 keropool1") ///
				drop(_cons _Istrata*) ///
				cells(b(star fmt(%12.2g) ) se(par(( )) fmt(%12.2g) ) qvalue(par([ ])  keep(treatment) fmt(2)) )  ///
				starlevels( * 0.10 ** 0.05 *** 0.01) ///
				varlabels(treatment "Treatment" elist(treatment \addlinespace )  ) ///
				stats(control_mean N, labels("Control mean" "Observations") fmt(2 %12.2gc 0 0))

MultiPartTabEnd, ///
				ncol(`nc') tabname(`tabname')					
					
					
					
					
					
					
					
					
					
					